<?php
namespace Doc\Controller;
use Think\Controller;

/**
 * 
 */
class ManageController extends Controller {
	
	function index() {
		$map['status'] = array('EGT', 0);
		$list = M('Category')->where($map)->select();
		$this->assign('list', $list);
		$this->display();
	}

	function add() {
		if (IS_POST) {
			$model = D('Category');
			if (!$model->create()) {
				$this->error($model->getError());
			} else {
				if ($model->add()) {
					$this->success('保存成功', U('Doc/Manage/index'));
				} else {
					$this->error('保存失败');
				}
			}
		} else {
			$this->display('edit');
		}
	}

	function edit($id) {
		if (IS_POST) {
			$model = D('Category');
			if (!$model->create()) {
				$this->error($model->getError());
			} else {
				if ($model->save()) {
					$this->success('保存成功', U('Doc/Manage/index'));
				} else {
					$this->error('保存失败');
				}
			}
		} else {
			$info = M('Category')->find($id);
			$this->assign('info', $info);
			$this->display();
		}
	}

	function cont($id) {
		$map['pid'] = $id;
		$list = M('Controller')->where($map)->order('sort asc')->select();
		$this->assign('list', $list);
		$this->display();
	}

	function contadd($pid) {
		if (IS_POST) {
			$model = D('Controller');
			if (!$model->create()) {
				$this->error($model->getError());
			} else {
				if ($model->add()) {
					$this->success('保存成功', U('Doc/Manage/cont?id='.I('get.pid')));
				} else {
					$this->error('保存失败');
				}
			}
		} else {
			$this->display('contedit');
		}
	}

	function contedit($id) {
		if (IS_POST) {
			$model = D('Controller');
			if (!$model->create()) {
				$this->error($model->getError());
			} else {
				if ($model->save()) {
					$this->success('保存成功');
				} else {
					$this->error('保存失败');
				}
			}
		} else {
			$info = M('Controller')->find($id);
			$this->assign('info', $info);
			$this->display();
		}
	}

	function action($id) {
		$map['pid'] = $id;
		$list = M('Action')->where($map)->order('sort asc')->select();
		$this->assign('list', $list);
		$this->display();
	}

	function actionadd() {
		if (IS_POST) {
			$model = D('Action');
			if (!$model->create()) {
				$this->error($model->getError());
			} else {
				if ($model->add()) {
					$this->success('保存成功', U('Doc/Manage/action?id='.I('get.pid')));
				} else {
					$this->error('保存失败');
				}
			}
		} else {
			$this->display('actionedit');
		}
	}

	function actionedit($id) {
		if (IS_POST) {
			$model = D('Action');
			if (!$model->create()) {
				$this->error($model->getError());
			} else {
				if ($model->save()) {
					$this->success('保存成功');
				} else {
					$this->error('保存失败');
				}
			}
		} else {
			$info = M('Action')->find($id);
			$this->assign('info', $info);
			$this->display();
		}
	}
}